<template>
    <el-dialog  title=""   visible :show-close="false" :append-to-body="true" class="wrap" @close="cancel" :close-on-click-modal="false">
         <i class="el-icon-close close" @click="cancel" style="color: white;z-index: 99;"></i>
		 <div class="bt">学生转班</div>
 		 <el-form label-width="100px" class="form">
                    <el-form-item label="原班级" class="select-block">
                        <el-input disabled v-model="form.oldClass"></el-input>
                    </el-form-item>
                    <el-form-item label="原班级老师" class="select-block">
                        <el-input disabled v-model="form.oldls"></el-input>
                    </el-form-item>
                    <el-form-item label="新班级" class="select-block">
                        <el-select v-model="form.newClass"  @change="getlslist" placeholder="请选择新班级" >
                            <el-option :label="v.mc" :value="v.id + ''" v-for="v in classList"></el-option>
                        </el-select>
                    </el-form-item>

                    <el-form-item label="新班级老师" class="select-block">
                        <el-input disabled v-model="vzwm"></el-input>
                    </el-form-item>
 		</el-form>
     <LoadingComponent v-if="isLoading"></LoadingComponent>
     <div class="btn">
     	<el-button type="primary" class="submit" @click="submit">确定</el-button>
		<el-button type="danger" class="submit" @click="cancel">退出</el-button>
                </div>
  </el-dialog>
</template>

<script type="text/javascript">
	import qs from 'qs'
    import LoadingComponent from 'components/loading'
    export default {
        components: { LoadingComponent },
        props: ['params', 'className'],
        data () {
            return {
              dialogVisible: false,
                isLoading:false,
                classList:[],
                multipleDelNum: [],
                classid: '',
                vzwm:'',
                form: {
                    oldClass: '',
                    newClass: ''
                },
                xsid:'',
            }
        },
        created () {
            console.log(this.params,'ssss')
			if(this.params.row){
				if(this.params.row.ysbjid){
	            	this.form.oldClass = this.params.row.ysbjmc
	            	this.form.bjid = this.params.row.ysbjid
	            	this.xsid = this.params.row.id
	            }else{
	            	this.form.oldClass = this.params.row.bjmc
	            	this.form.bjid = this.params.row.bjid
	            	this.xsid = this.params.row.id
	            }
	             this.form.oldls = this.params.row.lsmc
           		 this.form.lsid = this.params.row.lsid
			}else{
				this.form.oldClass = this.params.mc
	            this.form.bjid = this.params.bjid
                this.form.oldls = this.params.lsmc
       		    this.form.lsid = this.params.lsid
       		    this.xsid = this.params.xsid
			}
            
           
            this.getClass()
            // this.getStudent()
        },
        methods: {
            handleSelectionChange(val) {
                // this.multipleSelection = val;
                console.log(val)
            },
            change (val) {
                // console.log(val)
                this.classid = val;
            },
            getlslist(){
            	var logininfo = JSON.parse(localStorage.logininfo);
              this.searchLoading = true;
             var params2 = qs.stringify({
                      bjid:this.form.newClass
               })
             //执行
                 this.axios.post(this.$store.state.api + 'bj/lsbj',  params2 )
                 .then(res => {
      							let data = res.data.data.list;
      							this.vzwm = data[0].zwm;
      							this.vlsid = data[0].lsid;
                 }).catch(res => {
				})	
      			},
            submit () {
            	if(!this.form.newClass) {
					this.$message.warning('请选择新的班级');
					this.$store.state.loading = false;
					return;
				}
            	var logininfo = JSON.parse(localStorage.logininfo);
              this.searchLoading = true;
             var params2 = qs.stringify({
                       xsid: this.xsid,
                      zclsid:this.form.lsid,
                      zcbjid:this.form.bjid,
                      zrlsid:this.vlsid,
                      zrbjid:this.form.newClass,
                        yhid: logininfo.id + '',
        				xxid: logininfo.xxid + ''
               })
             //执行
                 this.axios.post(this.$store.state.api + 'xs/getzb',  params2 )
                 .then(res => {
                 	if(res.data.code == 1) {
                 		 this.$message.warning("该学生已成功转出!");
                    this.$emit('close',{type:'change',cancel:true})
                    this.$store.state.loading = false;
						} else {
                            this.$store.danger(res.data.msg)
							this.$store.state.loading = false;
						}
                 }).catch(res => {
                    this.$store.danger("服务器异常")
                    this.$store.state.loading = false;
				})	

                this.$emit('close',{type:'change',cancel:false})
            },
            cancel () {
              this.$emit('close',{type:'change',cancel:true})
            },
            // checkSelect (selection, row) {//点击单选select触发事件
            //     console.log(selection, row)
            //     let strID = [];
            //     selection.forEach(function(v,i){
            //         strID.push(v.id)
            //     })
            //     this.multipleDelNum = strID.join(",");
            //     console.log(this.multipleDelNum)
            // },
            // checkall (selection) {//点击全选select触发事件
            //     let strID = [];

            //     selection.forEach(function(v,i){
            //         strID.push(v.id)
            //     })
            //     // console.log(strID.join(","))
            //     this.multipleDelNum = strID.join(",");
            //     // console.log(strID)
            //     console.log(this.multipleDelNum)
            // },
            getClass () {
            	var logininfo = JSON.parse(localStorage.logininfo);
              this.searchLoading = true;
             var params2 = qs.stringify({
             	      bjid: this.form.bjid,
                      yhid: logininfo.id + '',
      				  xxid: logininfo.xxid + ''
               })
             //执行
                 this.axios.post(this.$store.state.api + 'bj/getbj',  params2 )
                 .then(res => {
                    this.classList = res.data.data.list
                    this.$store.state.loading = false;
                 }).catch(res => {
					 console.log(res)
                    this.$store.dispatch(res.data.msg)
                    this.$store.state.loading = false;
				})	
            }
            // getStudent (val) {
            //     console.log(val)
            //     this.axios.get(this.$store.state.api + 'xs/listxs',{
            //         params: {
            //             bjid: this.params.row.id
            //         }
            //     }).then( res => {
            //         console.log(res)
            //         // this.classList = res.data.data
            //         this.addStudentList = res.data.data.list;
            //         console.log(this.addStudentList)
            //     }).catch( res => {
            //         console.log(res)
            //     })
            // }
        }
    }
</script>

<style lang="less" scoped>
   .wrap {
 		text-align: center;
 	}
 	.bt{
			position: absolute;
			width: 100%;
			height: 50px;
			margin: 0 auto;
			top:0;
			left:0;
			background: #50BFFF;
			margin-bottom: 20px;
			color:white;
			text-align:left;
			line-height: 50px;
			font-size: 17px;
			padding-left: 15px;
		}
 	.form {
 		text-align: left;
 		margin-top: 20px;
 	}
 	.input {
             display: inline-block;
         }
 	.select-block {
 		display: block;
 		width:85%;
 	}
 	.submit {
 		width: 120px;
 	}
</style>
